@use "../core/color";
@use "../core/layout";
@use "../core/reset";
@use "../core/typography";

// Search page
// -----------
// Styles for the search page which displays the results
// of activity queries.

.search-result-nav {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40px;
}

.search-result-nav__title {
  color: color.$brand;
  margin: 0;
  line-height: 22px;
}

.search-result-nav__button {
  background-color: color.$grey-2;
  border: none;
  color: inherit;
  font-weight: bold;
  padding-top: 10px;
  padding-bottom: 10px;
  padding-left: 15px;
  padding-right: 15px;
  text-decoration: none;
}

// The result container holds all of the main content
// for the page and is in charge of layout
.search-result-container {
  display: flex;
  font-size: typography.$normal-font-size;
  margin-top: 40px;
  color: color.$grey-6;

  // Align the left and right edges of the search result list with the left and
  // right edges of the navbar content.
  padding-left: layout.$content-padding-left;
  padding-right: layout.$content-padding-right;

  max-width: layout.$content-max-width;
  margin-left: auto;
  margin-right: auto;
}

// search-results and search-zero map to the internal states of the page
// when there are actual results to be displayed or when there are none.
// They control the inner layouts for those columns
.search-results,
.search-result-zero {
  flex-basis: layout.$search-results-max-width;
  max-width: layout.$search-results-max-width;
  margin-right: layout.$search-results-margin-right;
}

.search-results__total {
  font-size: 17px;
  color: color.$brand;
  margin-bottom: 25px;
}

.search-results__list {
  // Remove default padding from <ol>
  list-style: none;
  padding-left: 0;
  padding-right: 0;
  margin-bottom: 40px;
}

.search-result-zero {
  background: color.$grey-2;
  padding: 30px;
}

.search-result-zero__title {
  margin-top: 0;
}

.search-result-zero__list {
  list-style-position: inside;
  padding-left: 0;
}

.search-result-zero__list-item {
  line-height: 35px;

  // Add additional padding between marker and item content.
  &:before {
    content: "";
    padding-left: 5px;
  }
}

.search-result__timeframe {
  color: color.$grey-4;
  font-weight: bold;
  padding-bottom: 10px;
  border-bottom: 1px solid color.$grey-2;
  margin-top: 30px;
}

.search-result__timeframe:first-child {
  margin-top: 0;
}

// A group of search results
.search-result-bucket {
  background-color: white;
  &:hover, &.is-expanded {
    background-color: color.$grey-2;
  }
  border-bottom: 1px solid color.$grey-3;
}

.search-result-bucket__header {
  display: flex;
  flex-direction: row;
  padding: 10px 10px;

  cursor: pointer;
  user-select: none;

  // The in-context arrow icon is hidden until the bucket header is hovered
  &:hover .search-result-bucket__incontext-icon {
    visibility: visible;
  }
}

.search-result-bucket__domain {
  flex-grow: 0;
  flex-shrink: 0;
  width: 120px;
  color: color.$grey-4;
  margin-right: 10px;
  word-wrap: break-word;
}

// The domain name in the bucket header is a clickable link on the left-hand
// side in desktop layouts. On smaller screens it spans the full width of the
// header and becomes plain text to avoid accidental clicks.
.search-result-bucket__domain-text {
  display: none;
}

.search-result-bucket__incontext-icon {
  // The in-context arrow icon is hidden until the bucket header is hovered
  visibility: hidden;
  width: 9px;
  height: 9px;
  color: color.$grey-4;
}

.search-result-bucket__title-and-annotations-count {
  display: flex;
  flex-grow: 1;
  min-width: 0;  // Without this min-width document titles containing really
                 // long words won't be wrapped (overflow-wrap: break-word
                 // won't work), see https://github.com/hypothesis/h/pull/3932
}

.search-result-bucket__title {
  color: color.$grey-6;
  text-decoration: none;
  font-weight: bold;
  flex-grow: 1;
  margin-right: 5px;
  overflow-wrap: break-word;
  min-width: 0;  // Without this min-width document titles containing really
                 // long words won't be wrapped (overflow-wrap: break-word
                 // won't work), see https://github.com/hypothesis/h/pull/3932
}

.search-result-bucket__annotations-count {
  font-weight: bold;
  width: 75px;
}

.search-result-bucket__annotations-count-container {
  width: 30px;
  color: color.$grey-6;
  background-color: color.$grey-2;
  text-align: center;
  border-radius: 2px;
  float: right;
}

.search-result-bucket__domain,
.search-result-bucket__title,
.search-result-bucket__annotations-count-container {
  padding-top: 5px;
  padding-bottom: 5px;
}

// The container for the contents of a search result bucket.
.search-result-bucket__content {
  padding-left: 10px;
  padding-right: 10px;
}

// The contents of a search result bucket which is shown when the bucket is
// expanded.
.search-result-bucket__annotation-cards-container {
  padding-left: 130px;
  display: none;
  &.is-expanded {
    display: flex;
  }
}

// Preferred width of annotation cards on large screens.
$annotation-card-width: 500px;

// The list of annotation cards in a bucket.
.search-result-bucket__annotation-cards {
  flex-basis: $annotation-card-width;
  flex-grow: 1;
  flex-shrink: 0;
  max-width: $annotation-card-width;
  padding-left: 0;
  padding-right: 0;
}

// Card displaying stats about a group of annotations in search results
.search-bucket-stats {
  @include typography.font-normal;
  display: flex;
  flex-direction: column;
  margin-left: 30px;
  word-wrap: break-word;
  min-width: 0;  // Without this min-width stats containing really
                 // long words won't be wrapped (word-wrap: break-word won't
                 // work).
}

$stats-icon-column-width: 20px;

.search-bucket-stats__icon {
  width: 12px;
  margin-right: $stats-icon-column-width - 12px;
}

.search-bucket-stats__key {
  display: flex;
  flex-direction: row;
  align-items: center;

  margin-bottom: 2px;
  color: color.$grey-6;
  font-weight: bold;
}

.search-bucket-stats__val {
  color: color.$grey-6;
  margin-bottom: 15px;
  margin-left: $stats-icon-column-width;
}

.search-bucket-stats__url,
.search-bucket-stats__username {
  word-break: break-all;
}

.search-bucket-stats__incontext-link {
  color: color.$grey-6;
  &:hover {
    text-decoration: underline;
  }
}

.search-bucket-stats__incontext-icon {
  position: relative;
  top: 1px;
  height: 9px;
  width: 9px;
}

.search-bucket-stats__collapse-view {
  @include reset.reset-button;

  & {
    color: color.$grey-6;
    margin-bottom: 15px;
    text-align: left;
  }
}

.search-bucket-stats__collapse-view-icon {
  margin-right: 4px;
  width: 12px;
}

.search-bucket-stats__collapse-view:focus {
  outline:0;
}

// On large tablets and below, display bucket titles beneath rather than
// alongside the domain name.
@media screen and (max-width: layout.$tablet-width + 100px) {
    .search-result-bucket__header {
      flex-direction: column;

      // Make domain and title containers stretch to the full width of the
      // column
      align-items: stretch;
    }

    .search-result-bucket__domain {
      width: 100%;
    }

    // Make domain plain text rather than a link to avoid the user accidentally
    // clicking it
    .search-result-bucket__domain-text {
      display: inline;
    }

    .search-result-bucket__domain-link {
      display: none;
    }

    .search-result-bucket__content {
      margin-top: 10px;
    }
}

// As the screen size gets smaller, just before it would have introduced a
// horizontal scrollbar move the user/group sidebar below the search results.
@media screen and (max-width: layout.$tablet-width + 250px) {
  .search-result-container {
    flex-direction: column;
    margin-top: 25px;
  }

  .search-result-nav {
    display: flex;
  }

  .search-result-hide-on-small-screens {
    display: none;
  }

  .search-results,
  .search-result-zero {
    margin-right: 0;
    flex-basis: auto;
  }

  .search-result-zero {
    padding-left: 10px;
    padding-top: 20px;
  }
}

// On large tablets and below left-align annotation cards in order to make more
// space for the stats to the right of the annotation card.
@media screen and (max-width: 1127px) {
  .search-result-bucket__annotation-cards-container {
    padding-left: 0;
  }
}

// On normal tablets and below, display annotation stats below annotation list
@media screen and (max-width: layout.$tablet-width - 50px) {

  .search-result-bucket__annotation-cards-container {
    flex-direction: column;
  }

  .search-result-bucket__annotation-cards {
    width: 100%;

    // Set the preferred height of the annotation card list based on its
    // contents.
    flex-basis: auto;
  }

  .search-bucket-stats {
    margin-left: 5px;
    margin-top: 10px;
  }
}

@media screen and (max-width: layout.$tablet-width) {
  // Align the left and right edges of the search result list with the left and
  // right edges of the navbar content.
  .search-result-container {
    padding-left: layout.$content-padding-left-on-small-screens;
    padding-right: layout.$content-padding-right-on-small-screens;
  }
}
